package com.fzrskj.cloud.free.core.utils;

import ms.core.support.Session;

import javax.servlet.http.HttpServletRequest;

/**
 * CloudContextUtils.
 *
 * @author zj.
 *         Created on 2018/11/9 0009.
 */
public class CloudContextUtils {
    private final static String KEY_USER = "C_USER";
    private final static String SESSION_KEY = "SK";
    private final static String HTTP_SERVLET_REQUEST = "HSR";
    private final static String PARAM_P = "P_P";
    private final static Integer ADMIN_ID = 1000;
    private final static String AGENT_ID = "A_ID";
    public final static Integer DEF_AGENT_ID = 0;
    private final static String SID_NAME = "SID";

    /**
     * 设置用户session.
     * @param session session.
     */
    public static void setSession(Session session) {
        ContextUtils.put(KEY_USER, session);
    }

    /**
     * 获取用户session.
     * @return Session.
     */
    public static Session getSession() {
        return ContextUtils.get(KEY_USER);
    }

    /**
     * 获取接口日志记录用ID（wc）.
     * @return
     */
    public static Integer getAdminId() {
        return ADMIN_ID;
    }

    /**
     * 设置会话密钥.
     * @param sessionKey session secret key.
     */
    public static void setSK(String sessionKey) {
        ContextUtils.put(SESSION_KEY, sessionKey);
    }

    /**
     * 获取会话密钥.
     * @return session secret key.
     */
    public static String getSK() {
        return ContextUtils.get(SESSION_KEY);
    }

    public static void setHttpServletRequest(HttpServletRequest request) {
        ContextUtils.put(HTTP_SERVLET_REQUEST, request);
    }

    public static HttpServletRequest getHttpServletRequest() {
        return ContextUtils.get(HTTP_SERVLET_REQUEST);
    }

    public static void setP(String p) {
        ContextUtils.put(PARAM_P, p);
    }

    public static String getP(){
        return ContextUtils.get(PARAM_P);
    }

    public static void setAgentId(Integer agentId) {
        ContextUtils.put(AGENT_ID, agentId);
    }

    public static Integer getAgentId() {
        return ContextUtils.get(AGENT_ID);
    }

    public static void setSid(String sid) {
        ContextUtils.put(SID_NAME, sid);
    }

    public static String getSid() {
        return ContextUtils.get(SID_NAME);
    }
}
